home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / lk_map.c < prev    next >
Text File  |  1993-08-23  |  8KB  |  392 lines

  1. /* lk_map.c */
  2.  
  3. /* 2 input node, 3 output node  userio program to
  4.    demonstrate Leonard/Kramer fault disgnosis problem */
  5. /* Assumptions:
  6.    (a)  training data in file are assumed to lie between
  7.    -1.0 and 1.0 (Extrapolation is shown between -1.5 and 1.5
  8.    (b)  No minmax table is used
  9.  
  10.    If used with save-best, set objective function to be UserIO.
  11. */
  12.  
  13.  
  14. /************************************************************************
  15.  * Copyright(C) 1987-1993 NeuralWare Inc                                *
  16.  * Penn Center West, IV-227, Pittsburgh, PA 15276                       *
  17.  * Telephone: (412) 787-8222    FAX: (412) 787-8220                     *
  18.  *                                                                      *
  19.  * All rights reserved.  No part of this program may be reproduced,     *
  20.  * stored in a retrieval system, or transmitted, in any form or by any  *
  21.  * means, electronic, mechanical, photocopying, recording or otherwise  *
  22.  * without the prior written permission of the copyright owner,         *
  23.  * NeuralWare, Inc.                                                     *
  24.  *                                                                      *
  25.  *                          PROPRIETARY NOTICE                          *
  26.  *                                                                      *
  27.  * This document is the property of NeuralWare, Inc. and contains       *
  28.  * trade-secrets and other proprietary information.  The information    *
  29.  * herein is reserved as proprietary to NeuralWare, and is not to be    *
  30.  * published, reproduced, copied, disclosed, used, or reverse           *
  31.  * engineered without the express written consent of a duly authorized  *
  32.  * representative of NeuralWare.                                        *
  33.  ************************************************************************
  34.  */
  35.  
  36. #define UIO_SERVER             1
  37. #define SERVER_EMULATOR_FILE   1
  38. #define SKIP_COMPAT_DATA       1
  39. #include "userutl.h"
  40. #include "uio_strc.h"
  41. #include "uio_tran.h"
  42. #include "uio_reqs.pro"
  43. #include "uio_cmds.pro"
  44.  
  45. #include <math.h>
  46.  
  47. #ifdef MAC
  48. #include "macuio.redef"
  49. #endif
  50.  
  51. #define DO_BLIT 1
  52.  
  53. #define W_WDTH  200  /* basic defining parameters */
  54. #define W_HGHT  200  /* height of graph */
  55. long file_count = 0l;
  56.  
  57. #define SBUF_ALC 200
  58. TEXT  sbuf[SBUF_ALC];
  59. int   back_color;
  60. int   on_color;
  61. #define COLOR_MAX 3
  62. int   color[COLOR_MAX];
  63. int   savebestf;    /* Save best flag */
  64.  
  65. float      xin, yin;       /* Real coords of recall point */
  66. int        x_rcl, y_rcl;   /* Graphics coords of recall point */
  67.  
  68. #define W0 1
  69. #define W1 2
  70.  
  71. #define PIXEL_WIDTH 3
  72.  
  73. #ifdef DO_BLIT
  74. #define BLIT_DIMX  (((W_WDTH-1)/PIXEL_WIDTH)+1)
  75. #define BLIT_DIMY  (((W_HGHT-1)/PIXEL_WIDTH)+1)
  76. TEXT    blit[BLIT_DIMY][BLIT_DIMX];
  77. #endif
  78.  
  79. NINT UIO_Init(file)
  80. TEXT *file;
  81. {
  82.   NINT       ret_val = UIO_OK;
  83.   NINT       xsize, ysize, ncolor, chrx, chry; /* graphics parameters */
  84.   TEXT      *filen;
  85.   FILE      *fp;
  86.  
  87.   savebestf = 0;
  88.  
  89.   /* Get screen parameters */
  90.   ug_gparms( &xsize, &ysize, &ncolor, &chrx, &chry);
  91.   
  92.   if ( ncolor < 8 ) {
  93.      PutStr("Require at least 8 colors or gray levels to run this demo\n");
  94.      return(UIO_ERROR);
  95.   }
  96.  
  97.   color[0] = 4;
  98.   color[1] = 6;
  99.   color[2] = 1;
  100.  
  101.   on_color   = 15;
  102.  
  103.   back_color = 0;
  104.   
  105.   /* Set up windows */
  106.   ug_window(W0, back_color, 20, 130, 20+W_WDTH, 130+W_HGHT);
  107.  
  108.   ug_window(W1, 0, 20, 47, 20+W_WDTH, 129);
  109.  
  110.   /* Get file count so we can calculate epochs */
  111.   ug_rdfileinf(&filen,0,&file_count);
  112.  
  113.   if (file_count <= 0l)
  114.      file_count = 1l;
  115.  
  116.   return(ret_val);
  117. }
  118.  
  119.  
  120. NINT UIO_Term(process)
  121. NINT process;
  122. {
  123.   NINT ret_val = UIO_OK;
  124.  
  125.   return(ret_val);
  126. }
  127.  
  128. NINT UIO_Attention()
  129. {
  130.   NINT ret_val = UIO_OK;
  131.  
  132.   return(ret_val);
  133. }
  134.  
  135.  
  136. NINT UIO_Learn_Start()
  137. {
  138.    NINT ret_val = UIO_OK;
  139.  
  140.    /* Set up learn file; use selected file */
  141.    ug_fileio("", 0, 1, 1, 1);
  142.  
  143.    return(ret_val);
  144. }
  145.  
  146. NINT UIO_Learn_Input(LayN, nPEs, Datap)
  147. NINT  LayN;
  148. NINT  nPEs;
  149. SREAL *Datap;
  150. {
  151.   NINT ret_val = UIO_OK;
  152.  
  153.   return(ret_val);
  154. }
  155.  
  156. NINT UIO_Learn_Output(LayN, nPEs, Datap)
  157. NINT  LayN;
  158. NINT  nPEs;
  159. SREAL *Datap;
  160. {
  161.   NINT ret_val = UIO_OK;
  162.  
  163.   return(ret_val);
  164. }
  165.  
  166.  
  167. NINT UIO_Learn_Result(LayN, nPEs, Datap)
  168. NINT  LayN;
  169. NINT  nPEs;
  170. SREAL *Datap;
  171. {
  172.    NINT  ret_val = UIO_OK;
  173.   
  174.    return(ret_val);
  175. }
  176.  
  177. NINT UIO_Learn_End()
  178. {
  179.   NINT ret_val = UIO_OK;
  180.  
  181.   return(ret_val);
  182. }
  183.  
  184. NINT UIO_Recall_Start()
  185. {
  186.   NINT ret_val = UIO_OK;
  187.   TEXT   *sp;
  188.   
  189.   x_rcl = PIXEL_WIDTH>>1;
  190.   y_rcl = PIXEL_WIDTH>>1;
  191.  
  192. #ifdef DO_BLIT
  193.   PutStr("Testing ...");
  194. #else
  195.   ug_winclr(W0);
  196.   ug_winclr(W1);
  197. #endif
  198.  
  199.   return(ret_val);
  200. }
  201.  
  202.  
  203. NINT UIO_Read(LayN, nPEs, Datap)
  204. NINT  LayN;
  205. NINT  nPEs;
  206. SREAL *Datap;
  207. {
  208.   NINT ret_val = UIO_OK;
  209.  
  210.   /* Assume data lies between -1.5 and 1,5 */
  211.   xin = ((3*x_rcl) / (float)W_WDTH) - 1.5;
  212.   yin = ((3*y_rcl) / (float)W_HGHT) - 1.5;
  213.  
  214.   Datap[0] = xin;
  215.   Datap[1] = yin;
  216.  
  217.   return(ret_val);
  218.  
  219. }
  220.  
  221. NINT UIO_Write(LayN, nPEs, Datap)
  222. NINT  LayN;
  223. NINT  nPEs;
  224. SREAL *Datap;
  225. {
  226.   NINT  ret_val = UIO_OK;
  227.   SREAL outval;
  228.   NINT  wx;
  229. #ifdef DO_BLIT
  230.   NINT  blitx, blity;
  231. #endif
  232.  
  233.   if (nPEs > 1) {
  234.      NINT  maxx;
  235.      SREAL maxval;
  236.      
  237.      maxval = -1000.0;
  238.      maxx = 0;
  239.  
  240.      /* Find PE with Max value */
  241.      for (wx=0; wx < nPEs; wx++) {
  242.         if (Datap[wx] > maxval) {
  243.            maxx = wx;
  244.            maxval = Datap[wx];
  245.         }
  246.      }
  247.      wx = maxx;
  248.   }
  249.  
  250.   if (wx >= COLOR_MAX)
  251.      wx = COLOR_MAX-1;
  252.   else if (wx < 0)
  253.      wx = 0;
  254.   
  255. #ifdef DO_BLIT
  256.   blitx = (x_rcl-1)/PIXEL_WIDTH;
  257.   blity = (y_rcl-1)/PIXEL_WIDTH;
  258.  
  259.   blit[blity][blitx] = color[wx];
  260. #else
  261.   if (color[wx] != back_color)
  262.      ug_boxf(W0, color[wx], 0,
  263.              x_rcl-1,y_rcl-1,x_rcl+1,y_rcl+1);
  264. #endif
  265.   
  266.   x_rcl += PIXEL_WIDTH;
  267.   if (x_rcl > W_WDTH) {
  268.      x_rcl = PIXEL_WIDTH>>1;
  269.      y_rcl += PIXEL_WIDTH;
  270. #ifdef DO_BLIT
  271.      /* Want to know we're still alive */
  272.      PutStr(".");
  273. #endif
  274.   }
  275.  
  276. #ifdef DO_BLIT
  277.   /* End of recall; now BLIT the image */
  278.   if (y_rcl >= W_HGHT) {
  279.  
  280.      ug_winclr(W0);
  281.      ug_winclr(W1);
  282.  
  283.      ug_blit(W0, 0, 0, 0, PIXEL_WIDTH, PIXEL_WIDTH,
  284.              BLIT_DIMX, BLIT_DIMY, (char *)&blit[0][0] );
  285.  
  286.      /* Following box represents limit of training data, assuming
  287.       it lies between -1.0 and 1.0 */
  288.      ug_box(W0, 7, 0,
  289.             (NINT)((SREAL)W_WDTH/6.0),
  290.             (NINT)((SREAL)W_HGHT/6.0),
  291.             (NINT)((SREAL)W_WDTH*5.0/6.0),
  292.             (NINT)((SREAL)W_HGHT*5.0/6.0),
  293.             0);
  294.  
  295.      ug_boxf(W1, color[0], 0, 15, 52, 35, 72);
  296.      ug_puts(W1,on_color,0,50,52,"Class 1 (Normal)",0);
  297.  
  298.      ug_boxf(W1, color[1], 0, 15, 28, 35, 48);
  299.      ug_puts(W1,on_color,0,50,28,"Class 2 (Fault 1)",0);
  300.  
  301.      ug_boxf(W1, color[2], 0, 15, 4, 35, 24);
  302.      ug_puts(W1,on_color,0,50,4,"Class 3 (Fault 2)",0);
  303.  
  304.      PutStr("\n");
  305.   }
  306.  
  307. #endif
  308.  
  309.   if (y_rcl >= W_HGHT)
  310.      return( UIO_EXIT);
  311.   else
  312.      return( UIO_OK);
  313.  
  314. }
  315.  
  316. NINT UIO_Write_Step(LayN, nPEs, Datap)
  317. NINT  LayN;
  318. NINT  nPEs;
  319. SREAL *Datap;
  320. {
  321.   NINT ret_val = UIO_OK;
  322.  
  323.   return(ret_val);
  324. }
  325.  
  326.  
  327. NINT UIO_Recall_Test(LayN, nPEs, Datap)
  328. NINT  LayN;
  329. NINT  nPEs;
  330. SREAL *Datap;
  331. {
  332.   NINT ret_val = UIO_OK;
  333.  
  334.   return(ret_val);
  335. }
  336.  
  337. NINT UIO_Recall_End()
  338. {
  339.   NINT ret_val = UIO_OK;
  340.  
  341.   if (!savebestf) {
  342.      PutStr("Hit <Enter> to continue:");
  343.      GetStr( );
  344.   }
  345.   return(ret_val);
  346. }
  347.  
  348. NINT UIO_Instrument(Instrument_id, nDataElems, DataElemp)
  349. NINT  Instrument_id;
  350. NINT  nDataElems;
  351. SREAL *DataElemp;
  352. {
  353.   NINT ret_val = UIO_OK;
  354.  
  355.   return(ret_val);
  356. }
  357.  
  358. /* FUNCTION */
  359. NINT UIO_ObjFunc(eoeflag, DataElemp)
  360. NINT  eoeflag;
  361. SREAL *DataElemp;
  362. {
  363.   NINT ret_val = UIO_OK;
  364.  
  365.   if (eoeflag)
  366.      savebestf = 0;   /* Clear save best flag */
  367.   else
  368.      savebestf = 1;   /* Tell recall we are in savebest mode */
  369.  
  370.   return(ret_val);
  371. }
  372.  
  373. NINT UIO_Rewind()
  374. {
  375.   NINT ret_val = UIO_OK;
  376.  
  377.   return(ret_val);
  378. }
  379.  
  380. NINT UIO_Explain(LayN, nPEs, Datap)
  381. NINT  LayN;
  382. NINT  nPEs;
  383. SREAL *Datap;
  384. {
  385.   NINT ret_val = UIO_OK;
  386.  
  387.   return(ret_val);
  388. }
  389.  
  390.  
  391.  
  392.